package dryven.codegen.asm.typeinfo;


public class UncompiledClassTypeInfo extends AbstractTypeInfo {

	private String _className;
	private TypeInfo _superType;
	
	public UncompiledClassTypeInfo(String className, TypeInfo superTypeInfo) {
		super();
		_className = className;
		_superType = superTypeInfo;
	}

	@Override
	public String getInternalClassName() {
		return _className.replace('.', '/');
	}

	@Override
	public String getTypeDescriptor() {
		return "L"+getInternalClassName()+";";
	}

	@Override
	public String getTypeName() {
		return _className;
	}

	@Override
	public boolean isBoolean() {
		return false;
	}

	@Override
	public boolean isByte() {
		return false;
	}

	@Override
	public boolean isChar() {
		return false;
	}

	@Override
	public boolean isDouble() {
		return false;
	}

	@Override
	public boolean isFloat() {
		return false;
	}

	@Override
	public boolean isInt() {
		return false;
	}

	@Override
	public boolean isInterface() {
		return false;
	}

	@Override
	public boolean isLong() {
		return false;
	}

	@Override
	public boolean isReference() {
		return true;
	}

	@Override
	public boolean isShort() {
		return false;
	}

	@Override
	public boolean isVoid() {
		return false;
	}

	@Override
	public boolean isArray() {
		return false;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UncompiledClassTypeInfo other = (UncompiledClassTypeInfo) obj;
		if (_className == null) {
			if (other._className != null)
				return false;
		} else if (!_className.equals(other._className))
			return false;
		return true;
	}

	@Override
	public TypeInfo getSuperType() {
		return _superType;
	}

	@Override
	public boolean isAssignableTo(Class<?> clazz) {
		try {
			return clazz.getName().equals(_className) || clazz.isAssignableFrom(Class.forName(_superType.getTypeName()));
		} catch (ClassNotFoundException e) {
			return false;
		}
	}

}
